```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Java final/finally/finalize 详解 | 技术小馆</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.8;
        }
        h1, h2, h3, h4 {
            font-family: 'Noto Serif SC', serif;
            font-weight: 600;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .code-block {
            background: #2d3748;
            border-radius: 0.5rem;
            color: #e2e8f0;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
        }
        .transition-all {
            transition: all 0.3s ease;
        }
        .first-letter {
            font-size: 3.5rem;
            line-height: 1;
            float: left;
            margin-right: 0.75rem;
            margin-bottom: -0.5rem;
            font-weight: 700;
            color: #4a5568;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6 max-w-6xl">
            <div class="flex flex-col md:flex-row items-center">
                <div class="md:w-1/2 mb-10 md:mb-0">
                    <h1 class="text-4xl md:text-5xl font-bold mb-4">Java 关键概念解析</h1>
                    <p class="text-xl md:text-2xl mb-8 opacity-90">final / finally / finalize 的深度解析</p>
                    <p class="text-lg opacity-80 mb-8">虽然这三个Java关键字和方法的名称相似，但它们在编程中的作用却截然不同。让我们一起来探索它们的奥秘。</p>
                    <div class="flex space-x-4">
                        <a href="#final" class="bg-white text-indigo-700 hover:bg-gray-100 px-6 py-3 rounded-full font-medium transition-all">final</a>
                        <a href="#finally" class="bg-indigo-700 text-white hover:bg-indigo-800 px-6 py-3 rounded-full font-medium transition-all">finally</a>
                        <a href="#finalize" class="bg-pink-600 text-white hover:bg-pink-700 px-6 py-3 rounded-full font-medium transition-all">finalize</a>
                    </div>
                </div>
                <div class="md:w-1/2">
                    <div class="mermaid">
                        graph TD
                            A[final/finally/finalize] --> B[final]
                            A --> C[finally]
                            A --> D[finalize]
                            B --> E[修饰类:不可继承]
                            B --> F[修饰方法:不可重写]
                            B --> G[修饰变量:不可修改]
                            C --> H[异常处理]
                            C --> I[确保执行]
                            D --> J[垃圾回收]
                            D --> K[资源清理]
                            D --> L[已过时]
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto px-6 py-16 max-w-6xl">
        <!-- Intro -->
        <section class="mb-20">
            <p class="text-xl text-gray-600 mb-8 leading-relaxed">
                <span class="first-letter">J</span>ava 语言中的 <code class="bg-gray-100 px-2 py-1 rounded">final</code>、<code class="bg-gray-100 px-2 py-1 rounded">finally</code> 和 <code class="bg-gray-100 px-2 py-1 rounded">finalize</code> 虽然名称相似，但它们在编程中的作用却截然不同。这篇文章将深入解析这三个关键概念的区别、用法和最佳实践，帮助你在实际开发中正确使用它们。
            </p>
            <div class="bg-blue-50 border-l-4 border-blue-500 p-6 rounded-r-lg">
                <div class="flex items-start">
                    <div class="flex-shrink-0 text-blue-500">
                        <i class="fas fa-lightbulb text-2xl"></i>
                    </div>
                    <div class="ml-3">
                        <h3 class="text-lg font-medium text-blue-800">关键区别</h3>
                        <p class="mt-1 text-blue-700">
                            <code>final</code> 是一个修饰符关键字，<code>finally</code> 是异常处理块，而 <code>finalize</code> 是 Object 类中的一个方法，三者功能完全不同。
                        </p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Final Section -->
        <section id="final" class="mb-20">
            <div class="flex items-center mb-10">
                <div class="bg-indigo-100 p-3 rounded-full mr-4">
                    <i class="fas fa-lock text-indigo-600 text-2xl"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800">final 关键字</h2>
            </div>
            
            <p class="text-lg text-gray-600 mb-8">
                <code>final</code> 是一个关键字，用于声明类、方法和变量。它的主要作用是防止更改，保证程序的稳定性和安全性。根据使用场景的不同，<code>final</code> 可以带来不同的效果。
            </p>
            
            <div class="grid md:grid-cols-3 gap-8 mb-12">
                <!-- 修饰类 -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover transition-all">
                    <div class="bg-indigo-600 p-4 text-white">
                        <h3 class="text-xl font-semibold">修饰类</h3>
                    </div>
                    <div class="p-6">
                        <p class="text-gray-600 mb-4">当一个类被声明为 <code>final</code> 时，这个类不能被继承。</p>
                        <div class="code-block p-4 rounded-lg mb-4">
                            <pre><code class="text-sm">public final class MyClass {
    // 该类不能被继承
}</code></pre>
                        </div>
                        <p class="text-gray-500 text-sm"><i class="fas fa-info-circle mr-2"></i>常用于工具类或安全敏感类</p>
                    </div>
                </div>
                
                <!-- 修饰方法 -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover transition-all">
                    <div class="bg-indigo-600 p-4 text-white">
                        <h3 class="text-xl font-semibold">修饰方法</h3>
                    </div>
                    <div class="p-6">
                        <p class="text-gray-600 mb-4">当一个方法被声明为 <code>final</code> 时，这个方法不能被子类重写。</p>
                        <div class="code-block p-4 rounded-lg mb-4">
                            <pre><code class="text-sm">public class MyClass {
    public final void myMethod() {
        // 该方法不能被子类重写
    }
}</code></pre>
                        </div>
                        <p class="text-gray-500 text-sm"><i class="fas fa-info-circle mr-2"></i>常用于防止关键算法被修改</p>
                    </div>
                </div>
                
                <!-- 修饰变量 -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover transition-all">
                    <div class="bg-indigo-600 p-4 text-white">
                        <h3 class="text-xl font-semibold">修饰变量</h3>
                    </div>
                    <div class="p-6">
                        <p class="text-gray-600 mb-4">当一个变量被声明为 <code>final</code> 时，这个变量的值在初始化后不能再改变。</p>
                        <div class="code-block p-4 rounded-lg mb-4">
                            <pre><code class="text-sm">public class MyClass {
    public static final int MY_CONSTANT = 10;
    // MY_CONSTANT 的值不能再改变
}</code></pre>
                        </div>
                        <p class="text-gray-500 text-sm"><i class="fas fa-info-circle mr-2"></i>常用于定义常量</p>
                    </div>
                </div>
            </div>
            
            <div class="bg-indigo-50 border-l-4 border-indigo-500 p-6 rounded-r-lg">
                <h3 class="text-lg font-medium text-indigo-800 mb-2">最佳实践</h3>
                <ul class="text-indigo-700 space-y-2">
                    <li class="flex items-start">
                        <i class="fas fa-check-circle mt-1 mr-2 text-indigo-500 flex-shrink-0"></i>
                        <span>将不会改变的常量声明为 <code>final</code></span>
                    </li>
                    <li class="flex items-start">
                        <i class="fas fa-check-circle mt-1 mr-2 text-indigo-500 flex-shrink-0"></i>
                        <span>不希望被继承的类应该声明为 <code>final</code></span>
                    </li>
                    <li class="flex items-start">
                        <i class="fas fa-check-circle mt-1 mr-2 text-indigo-500 flex-shrink-0"></i>
                        <span>关键方法如需防止子类修改可以声明为 <code>final</code></span>
                    </li>
                </ul>
            </div>
        </section>

        <!-- Finally Section -->
        <section id="finally" class="mb-20">
            <div class="flex items-center mb-10">
                <div class="bg-green-100 p-3 rounded-full mr-4">
                    <i class="fas fa-shield-alt text-green-600 text-2xl"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800">finally 块</h2>
            </div>
            
            <p class="text-lg text-gray-600 mb-8">
                <code>finally</code> 是一个用于异常处理的关键字，与 <code>try</code> 和 <code>catch</code> 一起使用。无论是否抛出异常，<code>finally</code> 块中的代码都会被执行，这使它成为资源清理的理想场所。
            </p>
            
            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div>
                    <h3 class="text-xl font-semibold text-gray-800 mb-4">基本用法</h3>
                    <div class="code-block p-6 rounded-lg mb-6">
                        <pre><code class="text-sm">try {
    // 可能抛出异常的代码
} catch (Exception e) {
    // 异常处理代码
} finally {
    // 资源释放代码，无论是否发生异常都会执行
}</code></pre>
                    </div>
                    <p class="text-gray-600">
                        <code>finally</code> 块通常用于关闭资源，如文件流、数据库连接等，确保这些资源在异常发生时也能正确关闭。
                    </p>
                </div>
                
                <div>
                    <h3 class="text-xl font-semibold text-gray-800 mb-4">执行顺序</h3>
                    <div class="code-block p-6 rounded-lg mb-6">
                        <pre><code class="text-sm">public int testFinally() {
    try {
        return 1;
    } finally {
        System.out.println("finally执行");
        // 这里会在return之前执行
    }
}</code></pre>
                    </div>
                    <p class="text-gray-600">
                        即使在 <code>try</code> 块或 <code>catch</code> 块中执行了 <code>return</code> 语句，<code>finally</code> 块仍然会在方法返回之前执行。
                    </p>
                </div>
            </div>
            
            <div class="bg-green-50 border-l-4 border-green-500 p-6 rounded-r-lg">
                <h3 class="text-lg font-medium text-green-800 mb-2">应用场景</h3>
                <ul class="text-green-700 space-y-2">
                    <li class="flex items-start">
                        <i class="fas fa-database mt-1 mr-2 text-green-500 flex-shrink-0"></i>
                        <span>数据库连接的关闭</span>
                    </li>
                    <li class="flex items-start">
                        <i class="fas fa-file-alt mt-1 mr-2 text-green-500 flex-shrink-0"></i>
                        <span>文件流的关闭</span>
                    </li>
                    <li class="flex items-start">
                        <i class="fas fa-network-wired mt-1 mr-2 text-green-500 flex-shrink-0"></i>
                        <span>网络连接的释放</span>
                    </li>
                    <li class="flex items-start">
                        <i class="fas fa-unlock mt-1 mr-2 text-green-500 flex-shrink-0"></i>
                        <span>锁的释放</span>
                    </li>
                </ul>
            </div>
        </section>

        <!-- Finalize Section -->
        <section id="finalize" class="mb-20">
            <div class="flex items-center mb-10">
                <div class="bg-yellow-100 p-3 rounded-full mr-4">
                    <i class="fas fa-trash-alt text-yellow-600 text-2xl"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800">finalize 方法</h2>
            </div>
            
            <p class="text-lg text-gray-600 mb-8">
                <code>finalize</code> 是 <code>Object</code> 类中的一个方法，用于对象被垃圾回收器回收前的清理操作。它主要是为了提供资源释放的最后机会，但由于其不可预测性和低效性，已经被认为是不推荐使用的。
            </p>
            
            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div>
                    <h3 class="text-xl font-semibold text-gray-800 mb-4">基本用法</h3>
                    <div class="code-block p-6 rounded-lg mb-6">
                        <pre><code class="text-sm">@Override
protected void finalize() throws Throwable {
    try {
        // 资源释放代码
    } finally {
        super.finalize();
    }
}</code></pre>
                    </div>
                    <p class="text-gray-600">
                        <code>finalize</code> 在过去常用于确保对象在垃圾回收前释放资源，但存在诸多问题。
                    </p>
                </div>
                
                <div>
                    <h3 class="text-xl font-semibold text-gray-800 mb-4">主要缺点</h3>
                    <div class="space-y-4">
                        <div class="flex items-start">
                            <div class="bg-yellow-100 rounded-full p-2 mr-3">
                                <i class="fas fa-exclamation-triangle text-yellow-600"></i>
                            </div>
                            <div>
                                <h4 class="font-medium text-gray-800">调用时间不确定</h4>
                                <p class="text-gray-600 text-sm">垃圾回收器何时调用 <code>finalize</code> 不确定</p>
                            </div>
                        </div>
                        
                        <div class="flex items-start">
                            <div class="bg-yellow-100 rounded-full p-2 mr-3">
                                <i class="fas fa-exclamation-triangle text-yellow-600"></i>
                            </div>
                            <div>
                                <h4 class="font-medium text-gray-800">性能问题</h4>
                                <p class="text-gray-600 text-sm">严重影响垃圾回收效率</p>
                            </div>
                        </div>
                        
                        <div class="flex items-start">
                            <div class="bg-yellow-100 rounded-full p-2 mr-3">
                                <i class="fas fa-exclamation-triangle text-yellow-600"></i>
                            </div>
                            <div>
                                <h4 class="font-medium text-gray-800">资源释放延迟</h4>
                                <p class="text-gray-600 text-sm">可能导致资源长时间不释放</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="bg-yellow-50 border-l-4 border-yellow-500 p-6 rounded-r-lg">
                <h3 class="text-lg font-medium text-yellow-800 mb-2">替代方案</h3>
                <p class="text-yellow-700 mb-4">
                    Java 9 以后引入了 <code>Cleaner</code> 和 <code>PhantomReference</code> 提供了更好的替代方案：
                </p>
                <ul class="text-yellow-700 space-y-2">
                    <li class="flex items-start">
                        <i class="fas fa-check-circle mt-1 mr-2 text-yellow-500 flex-shrink-0"></i>
                        <span>使用 <code>try-with-resources</code> 语句管理资源</span>
                    </li>
                    <li class="flex items-start">
                        <i class="fas fa-check-circle mt-1 mr-2 text-yellow-500 flex-shrink-0"></i>
                        <span>实现 <code>AutoCloseable</code> 接口</span>
                    </li>
                    <li class="flex items-start">
                        <i class="fas fa-check-circle mt-1 mr-2 text-yellow-500 flex-shrink-0"></i>
                        <span>使用 <code>Cleaner</code> 类(Java 9+)</span>
                    </li>
                </ul>
            </div>
        </section>

        <!-- Comparison Table -->
        <section class="mb-20">
            <h2 class="text-3xl font-bold text-gray-800 mb-10 text-center">三者对比</h2>
            <div class="bg-white rounded-xl shadow-md overflow-hidden">
                <table class="min-w-full divide-y divide-gray-200">
                    <thead class="bg-gray-50">
                        <tr>
                            <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">特性</th>
                            <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">final</th>
                            <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">finally</th>
                            <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">finalize</th>
                        </tr>
                    </thead>
                    <tbody class="bg-white divide-y divide-gray-200">
                        <tr>
                            <td class="px-6 py-4 whitespace-nowrap font-medium text-gray-900">类型</td>
                            <td class="px-6 py-4 whitespace-nowrap text-gray-500">关键字</td>
                            <td class="px-6 py-4 whitespace-nowrap text-gray-500">关键字</td>
                            <td class="px-6 py-4 whitespace-nowrap text-gray-500">方法</td>
                        </tr>
                        <tr>
                            <td class="px-6 py-4 whitespace-nowrap font-medium text-gray-900">作用</td>
                            <td class="px-6 py-4 whitespace-nowrap text-gray-500">防止修改</td>
                            <td class="px-6 py-4 whitespace-nowrap text-gray-500">确保执行</td>
                            <td class="px-6 py-4 whitespace-nowrap text-gray-500">垃圾回收前清理</td>
                        </tr>
                        <tr>
                            <td class="px-6 py-4 whitespace-nowrap font-medium text-gray-900">使用场景</td>
                            <td class="px-6 py-4 whitespace-nowrap text-gray-500">类/方法/变量</td>
                            <td class="px-6 py-4 whitespace-nowrap text-gray-500">异常处理</td>
                            <td class="px-6 py-4 whitespace-nowrap text-gray-500">对象回收</td>
                        </tr>
                        <tr>
                            <td class="px-6 py-4 whitespace-nowrap font-medium text-gray-900">是否推荐</td>
                            <td class="px-6 py-4 whitespace-nowrap text-green-600 font-medium">推荐</td>
                            <td class="px-6 py-4 whitespace-nowrap text-green-600 font-medium">推荐</td>
                            <td class="px-6 py-4 whitespace-nowrap text-red-600 font-medium">不推荐</td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </section>

        <!-- Summary -->
        <section class="bg-purple-50 rounded-xl p-8 md:p-12 mb-20">
            <h2 class="text-2xl md:text-3xl font-bold text-purple-800 mb-6">关键要点总结</h2>
            <div class="grid md:grid-cols-3 gap-6">
                <div class="bg-white p-6 rounded-lg shadow-sm">
                    <div class="text-purple-600 text-3xl mb-4">
                        <i class="fas fa-lock"></i>
                    </div>
                    <h3 class="text-lg font-semibold text-gray-800 mb-2">final</h3>
                    <p class="text-gray-600">用于限制修改的修饰符，可以应用于类、方法和变量。</p>
                </div>
                <div class="bg-white p-6 rounded-lg shadow-sm">
                    <div class="text-purple-600 text-3xl mb-4">
                        <i class="fas fa-shield-alt"></i>
                    </div>
                    <h3 class="text-lg font-semibold text-gray-800 mb-2">finally</h3>
                    <p class="text-gray-600">确保代码执行的异常处理块，常用于资源清理。</p>
                </div>
                <div class="bg-white p-6 rounded-lg shadow-sm">
                    <div class="text-purple-600 text-3xl mb-4">
                        <i class="fas fa-trash-alt"></i>
                    </div>
                    <h3 class="text-lg font-semibold text-gray-800 mb-2">finalize</h3>
                    <p class="text-gray-600">已过时的垃圾回收前清理方法，应使用替代方案。</p>
                </div>
            </div>
        </section>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-12">
        <div class="container mx-auto px-6 max-w-6xl">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-6 md:mb-0">
                    <h3 class="text-2xl font-bold text-white mb-2">技术小馆</h3>
                    <p class="text-gray-400">探索技术的无限可能</p>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" class="text-gray-300 hover:text-white transition-colors">
                        <i class="fas fa-globe mr-2"></i> http://www.yuque.com/jtostring
                    </a>
                </div>
            </div>
            <div class="border-t border-gray-800 mt-8 pt-8 text-center text-gray-500 text-sm">
                © 2023 技术小馆. 保留所有权利.
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'dark',
            flowchart: {
                useMaxWidth: false,
                htmlLabels: true,
                curve: 'basis'
            }
        });
        
        // 平滑滚动
        document.querySelectorAll('a[href^="#"]').forEach(anchor => {
            anchor.addEventListener('click', function (e) {
                e.preventDefault();
                document.querySelector(this.getAttribute('href')).scrollIntoView({
                    behavior: 'smooth'
                });
            });
        });
    </script>
</body>
</html>
```